package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    //根据用户的id和菜品的id或套餐的id查询购物车
    ShoppingCart findOne(ShoppingCart shoppingCart);

    //更新
    void update(ShoppingCart shoppingCartDB);

    //保存
    @Insert("insert into shopping_cart values(null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    //查询购物车
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> finByUserId(Long aLong);

    //清空购物车
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long aLong);

    //删除购物车中一个商品
    void deleteByUserIdAndDishId(ShoppingCart shoppingCart);

}
